/*
 * Copyright (C) 2022 KylinSoft Co., Ltd.
 *
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <https://www.gnu.org/licenses/>.
 */

#include <QDBusConnection>
#include <QProcess>
#include <QDebug>
#include "sidebarstate.h"

SidebarState::SidebarState(QObject *parent) : QObject(parent)
{
    //sidebar
    QDBusConnection::sessionBus().connect(QString("org.ukui.Sidebar"),
                                          QString("/org/ukui/Sidebar"),
                                          QString("org.ukui.Sidebar"),
                                          QString("sidebarStateChange"), this, SLOT(setSidebarState(QString)));

}

bool SidebarState::sidebarState()
{
    return sidebarValue;
}

void SidebarState::setSidebarShow()
{
    QProcess::startDetached("ukui-sidebar -s control");
}

void SidebarState::setSidebarState(QString state)
{
    if (state == "show") {
        sidebarValue = true;
    }
    if (state == "hide") {
        sidebarValue = false;
    }
}
